//package com.first.config.redis;
//
//import org.apache.log4j.Logger;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
//import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.context.annotation.Primary;
//import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
//import org.springframework.data.redis.core.RedisTemplate;
//import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
//import org.springframework.data.redis.serializer.StringRedisSerializer;
//
//import com.fasterxml.jackson.annotation.JsonAutoDetect;
//import com.fasterxml.jackson.annotation.PropertyAccessor;
//import com.fasterxml.jackson.databind.ObjectMapper;
//
//import redis.clients.jedis.JedisPoolConfig;
//@Configuration  
//@EnableAutoConfiguration  
//@ConditionalOnClass(JedisAutoConfig.class)
//public class SpringRedisConfig {
//	 private static Logger logger = Logger.getLogger(SpringRedisConfig.class);  
//	 @Autowired 
//	 private JedisPoolConfig config;
//	      
//	    @Bean("JedisConnectionFactory")  
//	    @Primary
////	    @ConfigurationProperties(prefix="spring.redis")  
//	    public JedisConnectionFactory getConnectionFactory(){  
//	        JedisConnectionFactory factory = new JedisConnectionFactory();  
//	        factory.setPoolConfig(config);  
//	        logger.info("JedisConnectionFactory bean init success."); 
//	        return factory;  
//	    }  
//	    
////	    
////	    @Bean("JedisCacheConnectionFactory")  
//////	    @ConfigurationProperties(prefix="spring.redis")  
////	    public JedisConnectionFactory JedisCacheConnectionFactory(){  
////	        JedisConnectionFactory factory = new JedisConnectionFactory();  
////	        factory.setPoolConfig(config);  
////	        factory.setDatabase(1);
////	        logger.info("JedisConnectionFactory bean init success."); 
////	        return factory;  
////	    }  
////	    
//	    
//	    @Bean("JedisUnitConnectionFactory")
////	    @ConfigurationProperties(prefix="spring.redis")  
//	    public JedisConnectionFactory JedisUnitConnectionFactory(){  
//	        JedisConnectionFactory factory = new JedisConnectionFactory();  
//	        factory.setPoolConfig(config);  
//	        factory.setDatabase(2);
//	        logger.info("JedisConnectionFactory bean init success."); 
//	        return factory;  
//	    }  
//	    
//	    
//	    
//	    @Bean
//		public RedisTemplate<Object, Object> redisTemplate(
//				JedisConnectionFactory connectionFactory) {
//			
//			RedisTemplate<Object, Object> template = new RedisTemplate<Object, Object>();
//			template.setConnectionFactory(connectionFactory);
//			
//			template.setKeySerializer(new StringRedisSerializer());
//			template.setHashKeySerializer(new StringRedisSerializer());
//			
//			
//	        //定义value的序列化方式
//	        Jackson2JsonRedisSerializer<Object> jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer<Object>(Object.class);
//	        ObjectMapper om = new ObjectMapper();
//	        om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
//	        om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
//	        jackson2JsonRedisSerializer.setObjectMapper(om);
//	        
//	        template.setValueSerializer(jackson2JsonRedisSerializer);
//	        template.setHashValueSerializer(jackson2JsonRedisSerializer);
//	        template.afterPropertiesSet();
//			
//			
//			return template;
//		}
//	    
//}
